﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Text
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {


            var uid = textUserName.Text;
            var pwd = textPassWord.Text;
            var rePwd = textRePwd.Text;

            var hasUid = !string.IsNullOrEmpty(uid);
            var hasPwd = !string.IsNullOrEmpty(pwd);
            var eqPwd = pwd == rePwd;


            string ConString = "server=.;database=Admin;uid=sa;pwd=123456;";
            SqlConnection sqlConnection = new SqlConnection(ConString);
            sqlConnection.Open();
            SqlCommand command = new SqlCommand("select * from Users", sqlConnection);

            if (hasUid && hasPwd && eqPwd)
            {
                MessageBox.Show("注册成功");
                Form1.users.Add(uid,pwd);
                command.CommandText=string .Format("insert into Users(Name,Pwd) values('{0}','{1}');", uid, pwd);
                this.Close();

            }
            else
            {
                MessageBox.Show("注册失败");

            }

        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
